//
//  FQDMySubscriptionEmptyView.m
//  FakeQDaily
//
//  Created by mewxiv on 9/20/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDMySubscriptionEmptyView.h"
#import "FQDLoginViewController.h"

#import "Masonry.h"

static NSString *kNotSubscribeButtonImageName = @"NoSubscription_button";
static NSString *kNotSubscribedCenterImageName = @"NoSubscription_image";
static NSString *kNotLoginedButtonImageName = @"NotLogin_button";
static NSString *kNotLoginedCenterImageName = @"NotLogin_image";

@interface FQDMySubscriptionEmptyView ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *descLabel;
@property (nonatomic, strong) UIImageView *centerImageView;

@end

@implementation FQDMySubscriptionEmptyView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self prepareUI];
        [self prepareConstraints];
    }
    return self;
}

- (void)prepareUI
{
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = FQDRegularFontWithSize(20.0f);
    _titleLabel.textColor = RGB(115, 115, 115);
    _titleLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_titleLabel];
    
    _descLabel = [[UILabel alloc] init];
    _descLabel.font = FQDRegularFontWithSize(12.0f);
    _descLabel.textColor = [UIColor blackColor];
    _descLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_descLabel];
    
    _centerImageView = [[UIImageView alloc] init];
    _centerImageView.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:_centerImageView];
    
    _actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_actionButton addTarget:self action:@selector(actionButtonTapped:)
            forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_actionButton];
}

- (void)actionButtonTapped:(id)sender
{
    if (self.delegate) {
        [self.delegate didSelectActionButtonInEmptyView:self];
    }
}

- (void)prepareConstraints
{
    WeakSelf;
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf).offset(20);
        make.centerX.equalTo(weakSelf);
        make.height.equalTo(@15);
    }];
    
    [_descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.titleLabel.mas_bottom).offset(20);
        make.centerX.equalTo(weakSelf);
    }];
    
    [_centerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.descLabel.mas_bottom).offset(20);
        make.left.equalTo(weakSelf).offset(20);
        make.right.equalTo(weakSelf).offset(-20);
        make.bottom.equalTo(weakSelf.actionButton.mas_top).offset(-40);
    }];
    
    [_actionButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf);
        make.bottom.equalTo(weakSelf).offset(-78);
        make.size.mas_equalTo(CGSizeMake(160, 42));
    }];
}

- (void)setType:(FQDMySubscriptionEmptyViewType)type
{
    _type = type;
    
    if (type == FQDMySubscriptionEmptyViewTypeNotLogined) {
        NSString *centerImageName = kNotLoginedCenterImageName;
        NSString *actionImageName = kNotLoginedButtonImageName;
        self.centerImageView.image = [UIImage imageNamed:centerImageName];
        [self.actionButton setImage:[UIImage imageNamed:actionImageName] forState:UIControlStateNormal];
        self.titleLabel.text = @"未登录";
        self.descLabel.text = @"登录后你关注的栏目更新可以在这里查看";
    } else if (type == FQDMySubscriptionEmptyViewTypeNotSubscribed) {
        NSString *centerImageName = kNotSubscribedCenterImageName;
        NSString *actionImageName = kNotSubscribeButtonImageName;
        self.centerImageView.image = [UIImage imageNamed:centerImageName];
        [self.actionButton setImage:[UIImage imageNamed:actionImageName] forState:UIControlStateNormal];
        self.titleLabel.text = @"你还没订阅栏目";
        self.descLabel.text = @"这里有很多满足你好奇心的栏目，现在就去看看吧！";
    }
}

@end
